
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <base href="/">
    <meta charset="utf-8">
    <title>发表问题 编辑问题 公用</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" href="res/layui/css/layui.css">
    <link rel="stylesheet" href="res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
    <div class="layui-container">
        <a class="fly-logo" href="/">
            <img th:src="${index[0].blogLogo}" alt="layui" width="200" height="40">
        </a>

        <ul class="layui-nav fly-nav-user">

            <!-- 未登入的状态 -->
            <shiro:guest>
                <li class="layui-nav-item">
                    <a class="iconfont icon-touxiang layui-hide-xs" href="user"></a>
                </li>
                <li class="layui-nav-item">
                    <a href="user">登入</a>
                </li>
                <li class="layui-nav-item">
                    <a href="user/regist.html">注册</a>
                </li>
            </shiro:guest>

            <!-- 登入后的状态 -->
            <shiro:user>
                <li class="layui-nav-item">
                    <a class="fly-nav-avatar" href="javascript:;">
                        <cite class="layui-hide-xs"><shiro:principal/></cite>
                        <i class="iconfont icon-renzheng layui-hide-xs" title="认证信息：layui 作者"></i>
                        <i class="layui-badge fly-badge-vip layui-hide-xs">VIP3</i>
                        <img src="https://tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg">
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="user/userInfo"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
                        <dd><a href="/"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
                        <hr style="margin: 5px 0;">
                        <dd><a href="" style="text-align: center;">退出</a></dd>
                    </dl>
                </li>
            </shiro:user>
        </ul>
    </div>
</div>

<div class="layui-container fly-marginTop">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <!--<div class="fly-none">没有权限</div>-->
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">发表新帖<!-- 编辑帖子 --></li>
                </ul>
                <div class=" layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">文章标题</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="edId" th:value="${blogAll.blogId}">
                                    <input type="text" name="title" lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input" th:value="${blogAll.blogTitle}">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">文章分类</label>
                                <div class="layui-input-inline">
                                    <select name="modules" lay-verify="required" lay-search="" id="blogText">
                                        <a th:each="blogclass:${blogClassifyList}" >
                                            <a th:if="${blogclass.classifyName == blogAll.blogClassifyName}">
                                                <option th:value="${blogAll.blogClassifyId}" th:text="${blogAll.blogClassifyName}" th:selected="${blogclass.classifyName == blogAll.blogClassifyName}?'selected':''"></option>
                                            </a>
                                            <a th:if="${blogclass.classifyName != blogAll.blogClassifyName}">
                                                <option th:value="${blogclass.classifyId}" th:text="${blogclass.classifyName}"></option>
                                            </a>
                                        </a>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                                <legend>文章内容</legend>
                            </fieldset>
                            <textarea class="layui-textarea" id="LAY_demo1" name="LAY_demo1" style="display: none" th:text="${blogAll.blogContent}"></textarea>
                        </div>
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="layuiadmin-app-form-submit">确认保存</button>
                        </div>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<footer th:replace="footer::header-fragment"></footer>

<script src="res/layui/layui.js"></script>
<script>
    layui.config({
        base: 'layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','layedit','element'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layedit = layui.layedit
            ,$ = layui.jquery,
            element = layui.element;
        form.render();
        //上传图片,必须放在 创建一个编辑器前面
        layedit.set({
            uploadImage: {
                url: 'admin/uploadPicture' //接口url
                ,type: 'post' //默认post
            }
        });
        //构建一个默认的编辑器
        var index2 = layedit.build('LAY_demo1');

        //编辑器外部操作
        var active = {
            content: function(){
                alert(layedit.getContent(index)); //获取编辑器内容
            }
            ,text: function(){
                alert(layedit.getText(index)); //获取编辑器纯文本内容
            }
            ,selection: function(){
                alert(layedit.getSelection(index));
            }
        };

        $('.site-demo-layedit').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var sta = 0;  //获取状态
            var content = layedit.getContent(index2);
            var blogText = $("#blogText").find("option:selected").text()
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post('user/updateUserBlog',{
                "blogId":field.edId,
                "title":field.title,
                "modules":field.modules,
                "status":sta,
                "content":content,
                "blogText":blogText
            },function (res){
                if (res.success){
                    if (sta==1){
                        layer.msg('发布文章成功', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        });
                    }else {
                        layer.msg('请等待审核', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        });
                    }

                    $("input[name='title']").val('');
                    layui.layedit.clearContent(index)
                }else {
                    layer.msg('发布失败', {
                        offset: '15px'
                        ,icon: 1
                        ,time: 1000
                    });
                }
            },'json');
        });
    });
</script>

</body>
</html>